//
//  TaskButtonTableViewCell.m
//  BaishidaiKnight
//
//  Created by mac book on 2019/1/28.
//  Copyright © 2019年 sy. All rights reserved.
//

#import "TaskButtonTableViewCell.h"


@interface TaskButtonTableViewCell ()

@property(nonatomic,strong) UIButton* merchantBtn;
@property(nonatomic,strong) UIButton* clientBtn;
@property(nonatomic,strong) UIButton* sendBtn;


@end

@implementation TaskButtonTableViewCell


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self =  [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        
        [self createSubviews];
        
    }
    return self;
}

#pragma mark - createSubviews
-(void)createSubviews{
    
    
    
    [self.contentView addSubview:self.merchantBtn];
    [self.contentView addSubview:self.clientBtn];
    [self.contentView addSubview:self.sendBtn];

    
    float width = 100;
    float space = (SCREEN_WIDTH- width*3)/4;
    
    [self.merchantBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.contentView).offset(10);
        make.left.equalTo(self.contentView).offset(space);
        make.size.mas_equalTo(CGSizeMake(width, 35));

    }];
    
    [self.clientBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.merchantBtn);
        make.left.equalTo(self.merchantBtn.mas_right).offset(space);
        make.size.equalTo(self.merchantBtn);
        
    }];
    
    
    [self.sendBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.clientBtn);
        make.left.equalTo(self.clientBtn.mas_right).offset(space);
        make.size.equalTo(self.clientBtn);
        
    }];
    
    
}

-(void)btnAction:(UIButton *)button{
    
    if (button.tag) {
        
        self.TaskButtonBlock(button.tag);
    }
    
}

-(void)setIsSend:(BOOL)isSend{
    
    _isSend = isSend;
    
    if (isSend) {
        [_sendBtn setTitle:@"确认送达" forState:UIControlStateNormal];

    }else{
        
        [_sendBtn setTitle:@"确认取货" forState:UIControlStateNormal];

    }
    
}

-(UIButton *)merchantBtn{
    
    if (!_merchantBtn) {
        
        _merchantBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_merchantBtn setBackgroundColor:getColor(whiteColor)];
        [_merchantBtn setTitleColor:getColor(@"c2d73c") forState:UIControlStateNormal];
        _merchantBtn.titleLabel.font = kFontNameSize(15);
        _merchantBtn.layer.borderColor = getColor(@"c2d73c").CGColor;
        _merchantBtn.layer.borderWidth = 1;
        _merchantBtn.layer.cornerRadius = 5;
        [_merchantBtn setTitle:@"联系商家" forState:UIControlStateNormal];
        [_merchantBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
        
        _merchantBtn.tag = 1001;
    }
    
    return _merchantBtn;
}


-(UIButton *)clientBtn{
    
    if (!_clientBtn) {
        _clientBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_clientBtn setBackgroundColor:getColor(whiteColor)];
        [_clientBtn setTitleColor:getColor(@"f4d000") forState:UIControlStateNormal];
        _clientBtn.titleLabel.font = kFontNameSize(15);
        _clientBtn.layer.borderColor = getColor(@"f4d000").CGColor;
        _clientBtn.layer.borderWidth = 1;
        _clientBtn.layer.cornerRadius = 5;
        [_clientBtn setTitle:@"联系买家" forState:UIControlStateNormal];
        [_clientBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
        _clientBtn.tag = 1002;

    }
    
    return _clientBtn;
}


-(UIButton *)sendBtn{
    
    if (!_sendBtn) {
        _sendBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_sendBtn setBackgroundColor:getColor(whiteColor)];
        [_sendBtn setTitleColor:getColor(@"f7a245") forState:UIControlStateNormal];
        _sendBtn.titleLabel.font = kFontNameSize(15);
        _sendBtn.layer.borderColor = getColor(@"f7a245").CGColor;
        _sendBtn.layer.borderWidth = 1;
        _sendBtn.layer.cornerRadius = 5;
        [_sendBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
        _sendBtn.tag = 1003;

    }
    
    return _sendBtn;
}



- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
